< previous page page_108 next page >

Page 108
True and False
True and False are used two different ways in Visual Basic. The constants True and False evaluate to 1 and 0, respectively. In Visual Basic, however, any value that is nonzero evaluates to True, and zero evaluate to False. True and False are keywords in Visual Basic. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim boolPerform As Boolean

boolPerform = True
...
If boolPerform Then
   ...
End If
Declaring Variables
There are many ways to declare variables. Although its not absolutely necessary to declare variables before you use them, every professional Visual Basic programmer will declare them. It is recommended that you check the Require Variable Declaration option in your Visual Basic environment. To set this value, select the Tools, Options menu. Checking this option forces the Option Explicit statement to be added to every module that makes you declare all variables before using them.
How you choose to declare a variable determines the characteristics of that variable, as discussed previously. The Dim statement is most commonly used to declare variables; however, there are other ways to declare variables, as youll learn later in this chapter:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim VariableName [As type]
When you declare variables, Visual Basic gives each variable a default value. This value will be different for the different data types. For numeric data types, it will always be zero (0). For a string variable, it will be a blank string (""). For a date variable, it will be December 30, 1899 12:00:00AM. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub FormInit()
   Dim intTemp As Integer
   Dim strName As String
End Sub

 
< previous page page_108 next page >

If you like this book, buy it!